package com.yh.commentmongodb.controller;

import com.yh.commentmongodb.entity.Comment;
import com.yh.commentmongodb.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

/**
 * @author wannabe
 * @createTime 23 18:16
 * @description
 */
@Controller
public class CommentController {
    @Autowired
    private CommentService commentService;
    @GetMapping("/")
    public String findAll(Model model){
        List<Comment> all = commentService.findAll();
        model.addAttribute("all",all);
        return "index";
    }
    @PostMapping("/insert")
    public String insert(Model model,Comment comment){
        commentService.insert(comment);
        return "redirect:/";
    }
    @GetMapping ("/remove")
    public String remove(Model model,String id){
        commentService.remove(id);
        return "redirect:/";
    }
}